﻿using System.Xml;

namespace BuzzX8.Xmpp.StreamElements.Stanza
{
    public class ResourceBindElement : StreamElement
    {
        public ResourceBindElement() : base("bind", XmppNamespaces.Bind)
        {
        }

        public JID JID { get; set; }
        public string Resource { get; set; }

        protected override void WritePayload(XmlWriter writer)
        {
            WriteResource(writer);
            WriteJid(writer);
        }

        private void WriteResource(XmlWriter writer)
        {
            if (!string.IsNullOrEmpty(Resource)) writer.WriteElementString("resource", Resource);
        }

        private void WriteJid(XmlWriter writer)
        {
            if (JID != null) writer.WriteElementString("jid", JID);
        }
    }
}
